//
//  LSZVisitorTableViewController.swift
//  醒浪微博
//
//  Created by 雷顺哲 on 16/7/9.
//  Copyright © 2016年 LSZ. All rights reserved.
//

import UIKit

class LSZVisitorTableViewController: UITableViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
    }
//    定义变量判断是否登录
    var isLogin: Bool = LSZUserAccountViewModel.sharedUserAccount.isLogin
    
//    创建访客视图,如果未登录就让它等于自定义的视图,如果登录了就使用系统的视图
    var vistorView: LSZVistorView?
    
    override func loadView()
    {
        if isLogin {
            super.loadView()
            
        } else {
            vistorView = LSZVistorView()
//            循环引用
            vistorView?.loginClosure = { [weak self] in
                
                self?.showOAuthLogin()
            }
            view = vistorView
            loadUpUI()
        }
    }
    
    
    private func loadUpUI() {
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", target: self , action: "registerAction")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", target: self , action: "loginAction")
    }
    
    
    @objc private func registerAction() {
        print("navigation的注册")
        showOAuthLogin()
    }
    
    @objc private func loginAction() {
        print("navigation的登录")
        showOAuthLogin()
    }
    
    
    
    
    //  OAuth登录页面
    private func showOAuthLogin() {
        let oAuthVC = LSZOAuthViewController()
        let nav = UINavigationController(rootViewController: oAuthVC)
        
        presentViewController(nav, animated: true, completion: nil)
    }
    
    
    
    
    
    
    
    
    
    

}
